package cn.com.service.impl;

import cn.com.beans.PResource;
import cn.com.mapper.PResourceMapper;
import cn.com.service.PResourceService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PResourceServiceImpl implements PResourceService {

    @Resource
    private PResourceMapper pResourceMapper;

    @Transactional
    @Override
    public void authorization(Integer accountId, Integer... resourceIds) {
        //清除授权
        this.pResourceMapper.deleteAuthorization(accountId);
        //重新授权
        this.pResourceMapper.authorization(accountId,resourceIds);
    }

    @Override
    public boolean deleteByIds(Integer... ids) {
        return pResourceMapper.deleteByIds(ids)>0;
    }

    @Override
    public boolean insert(PResource record) {
        return pResourceMapper.insert(record)>0;
    }

    @Override
    public List<PResource> findAll(PResource pResource) {
        return pResourceMapper.findAll(pResource);
    }

    @Override
    public List<PResource> findByRoleID(Integer roleId) {
        return pResourceMapper.findByRoleId(roleId);
    }

    @Override
    public PResource findByid(Integer id) {
        return pResourceMapper.findByid(id);
    }


    @Override
    public boolean update(PResource resource) {
        return pResourceMapper.update(resource)>0;
    }
}
